// var pageName = '12345';

(function (window) {
  window.addEventListener('load', onWindowLoaded);

  var pageName = '12345';
  var pageInfo = {
    pageName: 'front-end-training',
    pageSize: '100%',
    fileExtensions: ['html', 'css', 'js'],
    output: function () {
      console.log(this.pageName);
    },
  };
  var foo = {
    output: pageInfo.output,
  };
  var msgs = [
    'error',
    'you are right',
  ];

  // pageInfo.output();
  // pageInfo.output.call(foo);
  // pageInfo.output.call(null);
  // foo.output();

  function hoisting() {
    console.log(foo);

    var foo = 6;

    console.log(foo);

    foo = 10;

    // function foo() {}
  }

  function closureTest() {
    var funcs = [];

    for (var i = 0; i < 5; i++) {
      funcs[i] = function () {
        console.log(i);
      };

      // (function (i) {
      //   funcs[i] = function () {
      //     console.log(i);
      //   };
      // })(i);
    }

    funcs[0]();
    funcs[1]();
    funcs[2]();
    funcs[3]();
    funcs[4]();
  }

  function logMsgs() {
    var msgCtrlBtn = document.getElementById('msgCtrlBtn');

    msgCtrlBtn.addEventListener('click', function () {
      for (var i = 0; i < msgs.length; i++) {
        console.log(msgs[i]);
      }
    });
  }

  function logSomeMsg(msg, isNeeded) {
    if (!isNeeded) {
      return;
    }

    console.log(msg)
  }

  function onWindowLoaded() {
    var logCtrlBtn = document.getElementById('logCtrlBtn');

    logCtrlBtn.addEventListener('click', function (event) {
      console.log(event.target.id);
      logSomeMsg(event, true);
    });

    logMsgs();
    // closureTest();
    hoisting();

    console.log('javascript file');
  }

  function reverseString(str) {
    // todo
  }
})(window);
